package com.itlaobing.core;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcExperienceOracle {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        String driverClassName = "oracle.jdbc.driver.OracleDriver" ;
        String url = "jdbc:oracle:thin:@localhost:1521:T2081" ;
        String user = "itlaobing" ;
        String password = "itlaobing" ;

        // 1、加载驱动类
        Class<?> c = Class.forName( driverClassName );
        System.out.println( c );

        // 2、建立链接
        Connection connection = DriverManager.getConnection( url , user , password );

        // 3、创建 Statement 实例 ( 负责向数据库服务器发送SQL语句 和 接收数据库服务器返回的执行结果 )
        Statement statement = connection.createStatement();

        // 4、发送SQL给数据库服务器 ( 有些资料说这是执行SQL ) 并 获取数据库的执行结果
        int count = statement.executeUpdate( "insert into t_topicc(id,title) values (6,'kong')" );

        // 5、处理返回结果
        System.out.println( count );

        // 6、释放资源
        statement.close();
        connection.close();

    }

}
